#ifndef __KEY_H__
#define __KEY_H__

#include "soc_comm.h"

#define KEY_MAX_COUNT 1

struct key_s;
typedef void(*KEY_DOWN_FUNC)(struct key_s *key);

typedef enum KEY_STATE_E
{
    KEY_IDLE = 0,
    KEY_DLY,
    KEY_DOWN,
    KEY_UP,
    KEY_DCLICK,
    KEY_LONG
}KEY_STATE;

typedef struct key_s
{
    KEY_STATE state;
    int countMs; //
    uint8_t preVal;
    
    int lastClickMsDec;

    bool isInit;
    bool hasLongDown;

    SOC_GpioPort_t port;
    uint8_t pin;
    bool reverse;
}key_t;

void KeyInit(key_t *key, SOC_GpioPort_t port, uint8_t pin);
void KeySetReverse(key_t *key, bool reverse);
void KeySetDownCallBack(KEY_DOWN_FUNC cb);
void KeySetUpCallBack(KEY_DOWN_FUNC cb);
void KeySetDClickCallBack(KEY_DOWN_FUNC cb);
void KeySetLongDownCallBack(KEY_DOWN_FUNC cb);

#endif 